<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>学习时间</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/formSelects/formSelects-v4.css"/>
</head>
<style>
    .layui-inline{
        margin-bottom: 10px;
    }
</style>
<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form toolbar">


                <div class="layui-inline" >
                    <label class="layui-form-label">选择日期:</label>
                    <div class="layui-input-inline" style="width: 230px">
                        <input type="text" class="layui-input date-icon" id="searchDate" placeholder="请选择提交时间">
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">关键词:</label>
                        <div class="layui-input-inline mr0">
                            <input id="keyWords" class="layui-input" type="text" placeholder="姓名/手机号"/>
                        </div>
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">所属机构:</label>
                        <div class="layui-input-inline">
                            <select name="organizationId" id="organizationId"  lay-verType="tips"
                                    lay-filter="organization">
                                <option value="">全部</option>
                                <% for(organizations in organizationsList) { %>
                                <option value="${organizations.id}">${organizations.organizationName}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">所属校区:</label>
                        <div class="layui-input-inline">
                            <select name="schoolId" id="schoolId" lay-verType="tips" lay-filter="school">
                                <option value="">全部</option>
                                <% for(school in schoolList) { %>
                                <option value="${school.id}">${school.schoolName}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-item">
                        <label class="layui-form-label w-auto">所属班级:</label>

                        <div class="layui-input-inline">
                            <select name="classId" id="classId">
                                <option value="">全部</option>
                                <% for(classs in classsList) { %>
                                <option value="${classs.id}">${classs.className}</option>
                                <% } %>
                            </select>
                        </div>
                    </div>
                </div>


                <div class="layui-inline">
                    <button id="btnSearch" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>查询</button>
                    <button id="btnReset" class="layui-btn icon-btn"><i class="layui-icon">&#xe669;</i>重置</button>
                </div>


                <div class="layui-form-item" style="margin-top: 10px">
                    <table class="layui-table" id="childStudyTodayTable" lay-filter="childStudyTodayTable" style="margin-top: 30px"></table>
                </div>

            </div>
        </div>
    </div>
</div>


<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>

<script>
    layui.use(['layer', 'form', 'table', 'admin', 'laydate', 'upload', 'jquery', 'formSelects' ,'excel'],function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var formSelects = layui.formSelects;
        var myDate = new Date()

        //日期
        laydate.render({elem: '#searchDate',value: getDate(myDate)});

        var insTb = table.render({
            elem: '#childStudyTodayTable',
            url: 'childStudyToday/list',
            page: true,
            cellMinWidth: 100,
            title: '学习时间列表',
            text: {none: '暂无数据'},
            cols: [[
                {field: 'id', title: 'id' , width:50,hide: true},
                {field: 'rank', title: '排名' , width:60},
                {field: 'childName', title: '学员姓名' , width:200},
                {field: 'organizationName', title: '所属机构' , width:200},
                {field: 'schoolName', title: '所属校区' , width:200},
                {field: 'className', title: '所属班级' , width:200},
                {field: 'telNo', title: '手机号' , width:200},
                {field: 'studyTime', title: '今日已学（分钟）',width:200, templet:function (data){
                      if(data.studyTime){
                          return Math.floor(data.studyTime/60);
                      }else {
                          return 0;
                      }
                }},

            ]],
            done: function (res) {
                exportData = res.data;
            }
        });


        //搜索
        $('#btnSearch').click(function () {
            var organizationId = $('#organizationId').val();
            var schoolId = $('#schoolId').val();
            var classId = $('#classId').val();
            var keyWords = $('#keyWords').val();
            var searchDate = $('#searchDate').val();


            console.log(keyWords);
            insTb.reload({
                where: {
                    organizationId: organizationId,
                    schoolId: schoolId,
                    classId: classId,
                    keyWords: keyWords,
                    searchDate: searchDate
                }
            });
        });

        // 重置
        $('#btnReset').click(function () {
            $("#classId").val("");
            $("#schoolId").val("");
            $("#organizationId").val("");
            $("#keyWords").val("");
            window.location.reload();
        });


        //选择机构后筛选所负责的校区
        form.on('select(organization)', function (data) {
            changeSchool();
        });

        form.on('select(school)', function (data) {
            changeClasss();
        });


        function changeSchool() {
            $("#schoolId").empty();
            $("#classId").empty();
            form.render("select");//重新渲染 固定写法
            var organizationId=$("#organizationId").val();
            if(organizationId!=null && organizationId!=""){
                $.ajax({
                    url: '/admin/school/getListByOrganizationId?organizationId='+ organizationId,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#schoolId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $('#classId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $.each(data, function (index, item) {
                            $('#schoolId').append(new Option(item.schoolName, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                    }
                });
            }
        }

        function changeClasss() {
            $("#classId").empty();
            form.render("select");//重新渲染 固定写法
            var schoolId=$("#schoolId").val();
            if(schoolId!=null && schoolId!=""){
                $.ajax({
                    url: '/classs/getListBySchoolId?schoolId='+ schoolId,
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        $('#classId').append(new Option("全部", ""));// 下拉菜单里添加元素
                        $.each(data, function (index, item) {
                            $('#classId').append(new Option(item.className, item.id));// 下拉菜单里添加元素
                        });
                        form.render("select");//重新渲染 固定写法
                    }
                });
            }
        }

        //转换时间方法
        function getDate(date) {
            //也可以不传,获取的就是当前时间
            var time = new Date(date);
            var year= time.getFullYear()  //年
            var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
            var day = ("0" + time.getDate()).slice(-2); //日
            var mydate = year + "-" + month + "-" + day;
            return mydate
        }

    })

</script>

</body>
</html>